#include "controlDevice.h"
#include <stdlib.h>

/*

struct controlDevice
{
    char name[128]; // 设备名称
    int pin;  // 设别引脚
    int pinStatus; // 引脚状态
    int pinMode; // 引脚模式
    int (*deviceInit)(); // 初始化函数
    int (*open)(); // 打开函数
    int (*close)(); // 关闭函数
    int (*clearConfig)(); // 清除内存

    struct controlDevice *Next;
};


 */

int livingLightOpen(void);

int livingLightClose(void);

int livingLightClear(void);

int livingLightInit(void);


struct controlDevice livingLight = {
    .name       = "livingLight",
    .pin        = 21,
    .pinStatus  = HIGH,
    .pinMode    = OUTPUT,
    .deviceInit = livingLightInit,
    .open       = livingLightOpen,
    .close      = livingLightClose,
    .clearConfig= livingLightClear
};


int livingLightOpen(void)
{
    digitalWrite(livingLight.pin,LOW);
    livingLight.pinStatus = LOW;
}

int livingLightClose(void)
{
    digitalWrite(livingLight.pin,HIGH);
    livingLight.pinStatus = HIGH;
}

int livingLightClear(void)
{
    
}


int livingLightInit(void)
{
    pinMode(livingLight.pin,livingLight.pinMode);
    digitalWrite(livingLight.pin,livingLight.pinStatus);    
}

struct controlDevice* addLivingRoomToDeviceLink(struct controlDevice* phead)
{
    if(phead == NULL)
    {
        return &livingLight;
    }
    else
    {
        livingLight.Next = phead;
        phead = &livingLight;
        return phead;
    }

}

